home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / nasm095s.zip / RDOFF / RDLIB.C < prev    next >
C/C++ Source or Header  |  1997-07-27  |  2KB  |  89 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "rdoff.h"
  5. #include "rdlib.h"
  6.  
  7. int rdl_error = 0;
  8.  
  9. char *rdl_errors[3] = {
  10.     "no error","could not open file", "invalid file structure",
  11. };
  12.  
  13. int rdl_searchlib (struct librarynode * lib,
  14.            const char * label, rdffile * f)
  15. {
  16.     char        buf[257];
  17.     int            i;
  18.     void *        hdr;
  19.     rdfheaderrec    * r;
  20.  
  21.     rdl_error = 0;
  22.     lib->referenced ++;
  23.  
  24.     if (! lib->fp)
  25.     {
  26.     lib->fp = fopen(lib->name,"rb");
  27.     
  28.     if (! lib->fp) {
  29.         rdl_error = 1;
  30.         return 0;
  31.     }
  32.     }
  33.     else
  34.     rewind(lib->fp);
  35.  
  36.     while (! feof(lib->fp) )
  37.     {
  38.     i = 1;
  39.     while (fread(buf + i,1,1,lib->fp) == 1 && buf[i] && i < 257)
  40.         i++;
  41.     buf[0] = ':';
  42.  
  43.     if (feof(lib->fp)) break;
  44.  
  45.     if ( rdfopenhere(f,lib->fp,&lib->referenced,buf) ) {
  46.         rdl_error = 2;
  47.         return 0;
  48.     }
  49.     
  50.     hdr = malloc(f->header_len);
  51.     rdfloadseg(f,RDOFF_HEADER,hdr);
  52.     
  53.     while ((r = rdfgetheaderrec(f)))
  54.     {
  55.         if (r->type != 3)    /* not an export */
  56.         continue;
  57.  
  58.         if (! strcmp(r->e.label, label) )    /* match! */
  59.         {
  60.         free(hdr);            /* reset to 'just open' */
  61.         f->header_loc = NULL;        /* state... */
  62.         f->header_fp = 0;
  63.         return 1;
  64.         }
  65.     }
  66.  
  67.     /* find start of next module... */
  68.     i = f->data_ofs + f->data_len;
  69.     rdfclose(f);
  70.     fseek(lib->fp,i,SEEK_SET);
  71.     }
  72.  
  73.     lib->referenced --;
  74.     if (! lib->referenced)
  75.     {
  76.     fclose(lib->fp);
  77.     lib->fp = NULL;
  78.     }
  79.     return 0;
  80. }
  81.  
  82. void rdl_perror(const char *apname, const char *filename)
  83. {
  84.     fprintf(stderr,"%s:%s:%s\n",apname,filename,rdl_errors[rdl_error]);
  85. }
  86.  
  87.  
  88.  
  89.